import * as module from "@/tools/util";
import * as Request from '@/api/liubike';
import store from "@/tools/factory"
import { config, isDev } from '@/api/config';

import wx from '@/tools/wx'
import commonJs from '@/views/commonJs/common'
let that
let loginInfo = null;

/**
 * 转化:   this.data -> this._data
 * ev.detail -> ev.target
 */
export default {
    mixins: [commonJs],
    data() {
        return {
            userPhone: "暂未获取",
            loading: false,
            integral: 0,
            mileage: 0.00,
            authName: "未实名认证",
            badge: false,
            phoneHidden: true,
            showCancel: false,
            selectId: 1,
            count: 0,
            selectName: "开锁问题",
            list: [
                { id: 1, name: "开锁问题" },
                { id: 2, name: "还车问题" },
                { id: 3, name: "押金问题" },
                { id: 4, name: "账户余额问题" },
                { id: 5, name: "上报申诉" },
                { id: 6, name: "其他" }
            ],
        }
    },
    create() {
    },
    mounted() {
        that = this
        /*if (!store.get("loginInfo")) {
            return false
        }*/

        Request.getUserInfoV3().then(res => {
            let req = res.data;
            if (res.success) {
                that.setData({
                    userPhone: req.phone,
                    integral: req.integral,
                    mileage: (req.mileage / 1000).toFixed(2),
                    authName: req.identity ? "已实名" : "未实名认证"
                })
                if (req.badges.length > 0) {
                    that.setData({
                        badge: true
                    })
                }
            } else {
                that.setData({
                    badge: false
                })
            }
            Request.getMsgCount().then(res => {
                if (res.success) {
                    that.setData({
                        count: res.data
                    })
                }
            })
        })
    },
    methods: {
        onShareAppMessage: function () {
            return {
                title: '小遛共享',
                path: '/pages/index/index',
            }
        },
        onLoad: function (options) {
            that = this;
        },
        authMsg(event) {
            wx.requestSubscribeMessage({
                tmplIds: ['cHBghezFcyZPPWJuVaQ4QLomnSRTN5G0FtnxCNrfMWs'],
                success: function (res) {
                    console.log(res)
                },
                fail: function (err) {
                    console.log(err)
                }
            })
        },
        onShow() {
            if (!store.get("loginInfo")) {
                return false
            }
            Request.getUserInfoV3().then(res => {
                let req = res.data;
                if (res.success) {
                    that.setData({
                        userPhone: req.phone,
                        integral: req.integral,
                        mileage: (req.mileage / 1000).toFixed(2),
                        authName: req.identity ? "已实名" : "未实名认证"
                    })
                    if (req.badges.length > 0) {
                        that.setData({
                            badge: true
                        })
                    }
                } else {
                    that.setData({
                        badge: false
                    })
                }
                Request.getMsgCount().then(res => {
                    if (res.success) {
                        that.setData({
                            count: res.data
                        })
                    }
                })
            })
        },
        goAuth() {
            if (that._data.authName == "未实名认证") {
                wx.navigateTo({
                    url: `/authentication`
                });
            }
        },
        turnPage(e) {
            that.pointReport('view_myWallet', {}, that)
            let query = e.currentTarget.dataset['target'];
            console.log(query, e, 'query')
            if (query == 'msg') {
                store.set("wxWeb", `${config.msgURL}?token=${store.get("token")}`)
                wx.navigateTo({
                    url: `/webview`
                })
                return false
            }
            wx.navigateTo({
                url: `/${query}`
            });
        },
        tel() {
            console.log(that, 'that')
            that.pointReport('view_contactTel', {}, that)
            that.setData({
                phoneHidden: false
            })
        },
        close() {
            that.setData({
                phoneHidden: true
            })
        },
        phoneConfirm() {
            that.setData({
                phoneHidden: true
            })
            const loginInfo = store.get('loginInfo');
            const locationInfo = store.get("initLocationInfo");
            wx.makePhoneCall({
                phoneNumber: '4006076666',
            })
            /* wx.request({
                 url: `https://analytics.xlgxapp.com/log.gif?eventt=contactTel&content=${that._data.selectId}&test=${isDev}&time=${(new Date()).getTime()}`, //仅为示例，并非真实的接口地址
                 method: "GET",
                 header: {
                     'content-type': 'application/json',
                     'token': loginInfo.token || '',
                     'v': '1.0',
                     'osVersion': "weixin",
                     'appVersion': "2.35.0",
                     'appName': 'qx_miniProgram',
                     'lat': locationInfo ? locationInfo.lat : 0,
                     'lng': locationInfo ? locationInfo.lng : 0
                 },
                 success(res) {
                     wx.makePhoneCall({
                         phoneNumber: '4006076666',
                     })
                 },
                 fail(err) {
                     wx.showToast({
                         icon: "none",
                         title: `服务器报错啦`,
                         duration: 2000
                     })
                 }
             })*/
        },
        selectRechargeNum(ev) { // 选择充值金额
            const curTargetData = ev.currentTarget.dataset; // 当前点击目标
            // 选择时设置id和对应的金额
            that.setData({
                selectId: curTargetData.id,
                selectName: curTargetData.name
            });
        },
        getPhoneNumber(e) {
            // console.log(e);
        },
        goWebview() {
            store.set("wxWeb", `https://imxcx4.7x24cc.com/phone_webChat.html?accountId=N000000014228&chatId=6a652f0b-5ab0-468b-9eff-8d76572d2ca6`);
            this.$router.push({
                name: "webview"
            })
        },
        exit() {
            wx.showModal({
                title: "温馨提示",
                content: `你确定要退出当前账号吗？`,
                success(res) {
                    if (res.confirm) {
                        //移动登录信息,实名认证信息,注册路由,免押信息
                        // gwsign  zkl
                        module.removeStorages(['loginInfo', 'isAuth', 'regRoute', 'depositInfo', 'rideInfo', 'riding', 'reserve', 'appointment', 'orderno', 'gwsSalt']);
                        // 跳转到
                        wx.navigateBack({
                            delta: 1
                        })
                    }
                }
            });
        },
    }
}
